package cn.zxl.spring.holiday.job.web.controller;

import cn.zxl.spring.holiday.job.domain.Permission;
import cn.zxl.spring.holiday.job.qo.QueryObject;
import cn.zxl.spring.holiday.job.service.PermissionService;
import cn.zxl.spring.holiday.job.web.json.JsonResult;
import cn.zxl.spring.holiday.job.web.log.Log;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bofeifei
 * @since 2021-10-01
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @RequiresPermissions(value = {"权限展示","permission:list"},logical = Logical.OR)
    @Log(title = "权限展示")
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")QueryObject qo, Model model) {
        PageInfo<Permission> query = permissionService.query(qo);
        model.addAttribute("pageInfo",query);
        return "permission/list";
    }

    @ResponseBody
    @RequestMapping("/load")
    public JsonResult load() {
        JsonResult jsonResult = new JsonResult();
        try{
            permissionService.load();
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setSuccess(false);
            jsonResult.setMsg("请求失败");
        }
        return jsonResult;
    }
}

